﻿#include "wcssettingwid.h"
#include <QMessageBox>
#include "ui_wcssettingwid.h"
#include "cfgjsonrw.h"	

WCSSettingWid::WCSSettingWid(QWidget *parent)
	: QWidget(parent)
	, ui(new Ui::WCSSettingWid())
{
	ui->setupUi(this);
	setStyleSheet("font: 12pt \"Agency FB\"");
	Init();
}

WCSSettingWid::~WCSSettingWid()
{
	delete ui;
}


void WCSSettingWid::Init()
{
	auto cfg = cfgrw->GetWCSCfg();
	ui->lineEdit->setText(cfg.wcsIP());
	ui->lineEdit_2->setText(cfg.robIP() );

	ui->spinBox->setValue(cfg.wcsPort());
	ui->spinBox_2->setValue(cfg.robPort());

}
void WCSSettingWid::on_pushButton_clicked()
{
	WCSCfgJ cfg = {};
	cfg.type = 1;
	cfg.wcsIP() = ui->lineEdit->text();
	cfg.robIP() = ui->lineEdit_2->text();

	cfg.wcsPort() = ui->spinBox->value();
	cfg.robPort() = ui->spinBox_2->value();
	if (!cfgrw->UpdateWCSCfg(cfg)) {
		QMessageBox::warning(this, "ERROR", "保存失败");
	}
}
